package com.itheima.mapper;

import com.itheima.pojo.Chat;
import com.itheima.pojo.Friend;
import com.itheima.pojo.Group;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 员工管理
 */
@Mapper
public interface ChatMapper {

    @Select("select * from crowd where name = #{groupName}")
    Group getGroupByName(String groupName);

    @Select("select * from crowd where user_name = #{userName}")
    List<Group> groupList(String userName);


    @Select("select * from user where user_name = #{userName}")
    User getUserByName(String userName);

    @Select("select * from friend where user_name = #{userName}")
    List<Friend> friendList(String userName);

    @Insert("insert into chat(user_name, receiver_name, chat_content) " + " values(#{userName},#{receiverName},#{sendContent})")
    void storeMsg(String userName, String receiverName, String sendContent);


    @Select("select * from chat where user_name= #{friendName} and receiver_name= #{userName} order by chat_id DESC limit 1")
    Chat getMsg(String userName, String friendName);

    @Select("select * from chat where receiver_name= #{groupName} order by chat_id DESC limit 1")
    Chat getGroupMsg(String groupName);


    @Select("select * from chat where user_name= #{otherName} and receiver_name= #{userName} order by chat_id DESC limit 1")
    Chat getContentByName(String userName,String otherName);


    @Select("select * from friend where name = #{friendName} and user_name=#{userName}")
    Friend getFriendByName(String friendName, String userName);

    @Insert("insert into friend(user_name, name) " + " values(#{userName},#{friendName})")
    void addFriend(String friendName, String userName);



    @Insert("insert into crowd(user_name, name) " + " values(#{userName},#{groupName})")
    void insertGroup(String groupName, String userName);

    @Select("select * from chat where user_name = #{userName} and receiver_name = #{friendName} order by chat_id DESC")
    List<Chat> getChatLog(String friendName, String userName);

    @Select("select * from chat where receiver_name = #{groupName} order by chat_id DESC")
    List<Chat> getGroupLog(String groupName);

}
